package com.smartleanx.module.hrm.service.employee.listenser;

import java.util.Map;

import javax.annotation.Resource;

import org.springframework.stereotype.Component;

import com.alibaba.fastjson2.JSONObject;
import com.smartleanx.module.bpm.enums.task.BpmProcessInstanceStatusEnum;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEvent;
import com.smartleanx.module.bpm.event.BpmProcessInstanceStatusEventListener;
import com.smartleanx.module.hrm.eums.employee.ProcessDefinitionEnum;
import com.smartleanx.module.hrm.service.employee.EmployeeService;

import lombok.extern.slf4j.Slf4j;

/**
 * 员工外出流程状态监听器
 */
@Slf4j
@Component
public class BpmEmployeeGoOutListener extends BpmProcessInstanceStatusEventListener {

    @Resource
    private EmployeeService employeeService;

    @Override
    protected String getProcessDefinitionKey() {
        return ProcessDefinitionEnum.GO_OUT.getKey();
    }

    @Override
    protected void onEvent(BpmProcessInstanceStatusEvent event) {
        if (BpmProcessInstanceStatusEnum.APPROVE.getStatus().equals(event.getStatus())) {
            Map<String, Object> businessData = event.getBusinessData();
            System.out.println(businessData);

            // 员工ID
            String startUser = (String)businessData.get("startUser");
            JSONObject jsonObject = JSONObject.parseObject(startUser);
            Integer userId = jsonObject.getInteger("id");

            JSONObject formData = (JSONObject)businessData.get("formData");
            String wc_time_range = formData.getString("wc_time_range");
            String wc_reason = formData.getString("wc_reason");
            String wc_address = formData.getString("wc_address");
            log.info("外出时间：{}", wc_time_range);
            log.info("外出原因：{}", wc_reason);
            log.info("外出地点：{}", wc_address);

        } else if (BpmProcessInstanceStatusEnum.REJECT.getStatus().equals(event.getStatus())
            || BpmProcessInstanceStatusEnum.CANCEL.getStatus().equals(event.getStatus())) {
        }
    }
}
